/* The following serves to stretch the content div to the bottom of the margin images, or vice versa*/
function contentHeight(){
    setMaxHeight($(".rightMargin,#content,.leftMargin,#col2"),$("#content"));
};

function setMaxHeight(group, target) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		};
	});
	target.height(tallest);
};


function menuBordersThisPage(){
    /*
    Determines the name of the menu element for the current URL, and
    passes it menuBorders to draw the menu borders.
    */
    pageName=location.pathname.replace(/\//g,'')
    if ($('.gallery-photo')[0]) {
        pageName='photos'
    };
    
    if (pageName.indexOf('project')!=-1) {
        pageName='projects'
    };

    if (pageName=='project') {
        pageName='projects'
    };
    
    if ($('.photo')[0]) {
        pageName='photos'
    };

    if (pageName.indexOf('gallery')!=-1) {
        pageName='photos'
    };
    
    menuBorders(pageName);
};

function menuBorders(currentPageName){
    //
    if (currentPageName){
        currentLi= $("#"+currentPageName);
        menuBordersLi(currentLi);
    };
};

function menuBordersLi(currentLi){
    //Given the element id of a menu item, draws borders around it as necessary for the menu. 
    $("li a").parent().css('border','none');
    $("li a").parent().css('color','gray');
    
    currentLi.children().css('color', 'black');
    currentLi.css('border','thin black solid');
    currentLi.nextAll().css('border-bottom','thin black solid');
    currentLi.nextAll().css('border-top','none');
    currentLi.prevAll().css('border-bottom','none');
    currentLi.prevAll().css('border-top','thin black solid');
    if (currentLi.attr('id')=='search'){
        currentLi.children().children().attr('src','/site_media/mag_glass_black.gif')
    }
    
};


$(document).ready(function() {
$(".hidden").hide()
$('input[name=honeypot]').hide()

$(".dinosaur").hover(
    function(){

        $("#dinosaurBrain").fadeIn()
  
    },
    function(){
        $("#dinosaurBrain").fadeOut()
    }
)

$("#tronImg").hide();
$("#tronLink").hover(
    function(){
        $("#tronImg").fadeIn()
    },
    function(){
        $("#tronImg").fadeOut()
    }

    );

//hide the all of the element with class collapse_body
$(".collapse_body").hide();
$(".collapse_head").addClass("plus_icon");

//toggle on click header
$(".collapse_head").click(function()
{
$(this).next(".collapse_body").slideToggle(600);
$(this).toggleClass("plus_icon");

});


/*menu flavor text*/
$("li").hover(
        function(){
        subtitle=$("#subtitle");
            
            if ($(this).attr("id")=="search"){
                subtitle.text("searchable brain.");
                $(this).children().children().attr('src','/site_media/mag_glass_black.gif')
            }
            else{
                subtitle.text(($(this).attr("flavorText")));
            };
            $('#flavTxtSE').fadeOut()
            $("#"+$(this).attr("id")+"Img").fadeIn()

        },
        
        function(){
        subtitle.text($('#pageTitle').text());
        $('#search').children().children().attr('src','/site_media/mag_glass_gray.gif')
        $("#"+$(this).attr("id")+"Img").fadeOut()
        }
);
        
$(".needsFlavor").hover(
    function(){
        /*selecting the relevant menu item using the second class name of the hovered element,
          then faking a hover
        */
        res=$('#'+$(this).attr('class').split(' ')[1]);
        res.mouseenter();
        res.children().css('color','black');
        },
    function(){
        res=$('#'+$(this).attr('class').split(' ')[1]);
        res.mouseleave();
        res.children().mouseleave();
        res.children().css('color','');
        }
);

menuBordersThisPage();

$('div.object').hover(
    
    function() {
        $(this).addClass('objectHover');
    },
    
    function() {
        $(this).removeClass('objectHover');
    }

);

$('.searchable li').quicksearch({
  position: 'before',
  attached: 'ul.searchable',
  labelText: '',
  loaderText: '',
  delay: 100});

$('table.searchable tr').quicksearch({
  position: 'before',
  attached: 'table.searchable:first'});
 
 $("a.closeDiv").click(function () {
		  $(this).parent().hide();
		});

/*$("#footerLinks").hover(
		  function() {$(".footer").fadeIn("slow")},
		  function() {$(".footer").fadeOut("slow")}
);*/

function linkHover(hoverLink,image){

$(hoverLink).bind('mouseover',
		  function() {
              $(image).stop().css("opacity", "1.0").fadeIn("slow");
              $('')
/*			  $(hoverLink).css("background","gray");*/

		  });
$(hoverLink).bind('mouseout',
		  function() {
			  $(image).stop().fadeOut("slow");
/*			  $(hoverLink).css("background","black");*/

		  }
);



};

/*dropdown (well, up actually) menu code from http://css-tricks.com/simple-jquery-dropdowns/*/
$("ul.menu li").hover(
	function(){
		$(this).addClass("hover")
		$('ul:first',this).css('visibility','visible')
        alert("fooble!")

	},

	function(){
        $(this).removeClass("hover")
        $('ul:first',this).css('visibility', 'hidden')
        $("#"+$(this).attr("id")+"Img").fadeOut()
	});
        

	$("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");
/* end dropdown menu code */
	
});
